import React, { Component } from 'react';
import { Icon, NavBar } from 'antd-mobile';
import { hashHistory } from 'react-router';
import styles from '../styles/App.css';
import $ from 'jquery';
import CookieUtil from './utils/CookieUtil';

class App extends Component {
    constructor(props){
        super(props);
        this.state = {
            title: '个性化定制',
            userInfo: '',
        }
    }

    componentWillMount() {
        /*const openid = CookieUtil.getCookie('openid');
         if(!openid){
         const appid = 'wx06c0a14577c208b3';
         const appsecret = 'c70fb7407b2f010933715a92837446e5';
         const scope = 'snsapi_userinfo';
         const state = 'thisisstate';
         const redirect_uri = 'http://vhjmlw.free.ngrok.cc/handleCode';
         let url = `https://open.weixin.qq.com/connect/oauth2/authorize`;
         url += `?appid=${appid}`;
         url += `&redirect_uri=${encodeURIComponent(redirect_uri)}`;
         url += `&response_type=code`;
         url += `&scope=${scope}`;
         url += `&state=${state}#wechat_redirect`;
         /!*$.ajax({
         url,
         type: 'GET',
         success: (response)=>{
         console.log(response);
         },
         error: (error)=>{
         throw error;
         },
         });*!/
         window.location.href = url;
         }*/

        /*const openid = CookieUtil.getCookie('openid');
        if(!openid){
            const params = HandleSearch.parseQueryString(window.location.href);
            const { code, state } = params;
            alert(code);
            alert(state);
            $.ajax({
                url: `/handleCode?code=${code}&status=${status}`,
                type: 'GET',
                success: (response)=>{
                    console.log(response);

                },
                error: (err)=>{
                    if(err){
                        throw err;
                    }
                }
            });
        } else {

        }*/
    }

    componentDidMount() {

    }

    render() {
        return (
            <div className={styles.App}>
                {/* <NavBar
                    mode="light"
                >{this.state.title}</NavBar> */}
                <div>
                    {this.props && this.props.children && React.cloneElement(this.props.children, {
                        changeTitle: title => this.setState({ title })
                    }) || 'no content'}
                </div>
            </div>
        );
    }
}

export default App;
